package com.restkeeper.gateway.config.customCode.config;


import org.apache.commons.lang.StringUtils;

import java.util.Map;

import static com.restkeeper.gateway.config.customCode.config.CharConfig.decodeConfig;
import static com.restkeeper.gateway.config.customCode.config.CharConfig.encodedConfig;


public class CustomCodeConfig {
    public static String encoded(String code){
        Map<String, String> encodedMap = encodedConfig();
        for (String key : encodedMap.keySet()) {
            code=code.replace(key, encodedMap.get(key));
        }
        return code;
    }

    public static String formatCode(String str) {
        if (StringUtils.isBlank(str)) {
            return "";
        }
        if (!str.startsWith("%eB") || !str.endsWith("%nD")) {
            return "";
        }
        Map<String, String> decode = decodeConfig();
        for (String key : decode.keySet()) {
            str=str.replace(key, decode.get(key));
        }
        return str;
    }





}
